package com.galaxy.device.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.galaxy.common.core.domain.R;
import com.galaxy.common.log.annotation.Log;
import com.galaxy.common.log.enums.BusinessType;
import com.galaxy.common.web.core.BaseController;
import com.galaxy.device.domain.DeviceStatus;
import com.galaxy.device.domain.bo.DeviceStatusBo;
import com.galaxy.device.domain.vo.DeviceStatusVo;
import com.galaxy.device.service.IDeviceStatusService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 设备状态管理控制器
 */
//@Validated
@RestController
@RequiredArgsConstructor
@RequestMapping("/status")
public class DeviceStatusController extends BaseController {

    private final IDeviceStatusService deviceStatusService;

    /**
     * 查询设备状态列表
     */
    @GetMapping("/list")
//    @SaCheckPermission("device:status:list")
    public R<List<DeviceStatusVo>> list(DeviceStatusBo bo) {
        return R.ok(deviceStatusService.queryList(bo));
    }

    /**
     * 获取设备状态详细信息
     */
    @GetMapping("/{id}")
//    @SaCheckPermission("device:status:query")
    public R<DeviceStatusVo> getInfo(@PathVariable Long id) {
        return R.ok(deviceStatusService.getInfo(id));
    }

    /**
     * 新增设备状态
     */
    @PostMapping
    @Log(title = "设备状态管理", businessType = BusinessType.INSERT)
//    @SaCheckPermission("device:status:add")
    public R<Void> add(@Validated @RequestBody DeviceStatusBo bo) {
        deviceStatusService.add(bo);
        return R.ok();
    }

    /**
     * 修改设备状态
     */
    @PutMapping
    @Log(title = "设备状态管理", businessType = BusinessType.UPDATE)
//    @SaCheckPermission("device:status:edit")
    public R<Void> update(@Validated @RequestBody DeviceStatusBo bo) {
        deviceStatusService.update(bo);
        return R.ok();
    }

    /**
     * 根据设备编号修改设备状态
     */
    @PutMapping("/updateByDeviceNo")
    @Log(title = "设备状态管理", businessType = BusinessType.UPDATE)
//    @SaCheckPermission("device:status:edit")
    public R<Void> updateByDeviceNo(@Validated @RequestBody DeviceStatusBo bo) {
        deviceStatusService.updateByDeviceNo(bo);
        return R.ok();
    }

    /**
     * 删除设备状态
     */
    @DeleteMapping("/{id}")
    @Log(title = "设备状态管理", businessType = BusinessType.DELETE)
    @SaCheckPermission("device:status:remove")
    public R<Void> delete(@PathVariable Long id) {
        deviceStatusService.delete(id);
        return R.ok();
    }

    /**
     * 批量删除设备状态
     */
    @DeleteMapping("/batch/{ids}")
    @Log(title = "设备状态管理", businessType = BusinessType.DELETE)
    @SaCheckPermission("device:status:remove")
    public R<Void> deleteBatch(@PathVariable Long[] ids) {
        deviceStatusService.deleteBatch(ids);
        return R.ok();
    }

    /**
     * 更新设备在线状态
     */
    @PutMapping("/online/{deviceId}")
    @Log(title = "设备状态管理", businessType = BusinessType.UPDATE)
//    @SaCheckPermission("device:status:edit")
    public R<Void> updateOnline(@PathVariable Long deviceId) {
        deviceStatusService.updateOnline(deviceId);
        return R.ok();
    }

    /**
     * 更新设备在线状态
     */
    @PutMapping("/onlineByDeviceNo/{deviceNo}")
    @Log(title = "设备状态管理", businessType = BusinessType.UPDATE)
//    @SaCheckPermission("device:status:edit")
    public R<Void> updateOnlineByDeviceNo(@PathVariable String deviceNo) {
        deviceStatusService.updateOnlineByDeviceNo(deviceNo);
        return R.ok();
    }


}
